<?php
/**
 *
 * User: 梁晓伟  lxw11109@gmail.com
 * Date: 2017-09-05
 * Time: 12:12
 */

namespace App\Http\Middleware;

use App\Http\Controllers\Controller;
use App\Models\UserManager;
use App\Models\UserManagerLog;
use Closure;
use Illuminate\Support\Facades\Auth;

class EnableCrossRequestMiddleware extends Controller
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request $request
     * @param  \Closure $next
     * @param  string|null $guard
     * @return mixed
     */
    public function handle($request, Closure $next, $guard = null)
    {
        $response = $next($request);
        $origin = $request->server('HTTP_ORIGIN') ? $request->server('HTTP_ORIGIN') : '';
        //\Log::info("跨域$origin");
        $allow_origin = [
            "http://localhost:3336",
            "http://localhost:3335",
            "http://192.168.110.222:3336",
            "http://192.168.110.222:3335",
            "http://101.200.207.61:9131"


        ];

//        $response->header('Access-Control-Allow-Origin', $origin);
//        $response->header('Access-Control-Allow-Headers', 'Content-Type, Accept, X-Requested-With, remember-me,accessToken,accesstoken,Origin,Referer,User-Agent,content-type,application/json');
//        $response->header("Access-Control-Max-Age", "3600");
//
//        $response->header('Access-Control-Expose-Headers', '*');
//        $response->header('Access-Control-Allow-Methods', 'GET,POST, PATCH, PUT, OPTIONS,TRACE,HEAD,DELETE');
//        $response->header('Access-Control-Allow-Credentials', 'true');
//        if (in_array($origin, $allow_origin)) {
//            $response->header('Access-Control-Allow-Origin', $origin);
//            $response->header('Access-Control-Allow-Headers', 'accessToken,accesstoken,Accept,Origin,Referer,User-Agent,content-type,application/json');
//            $response->header('Access-Control-Expose-Headers', '*');
//            $response->header('Access-Control-Allow-Methods', 'GET,POST,PATCH,PUT,OPTIONS,TRACE,HEAD,DELETE');
//            $response->header('Access-Control-Allow-Credentials', 'true');
        //}
        return $response;

    }
}
